function el(id)
{
	return document.getElementById(id);
}


/**
 * Returns a random integer between min and max
 * Using Math.round() will give you a non-uniform distribution!
 */
function getRandomInt(min, max) 
{
    return Math.floor(Math.random() * (max - min + 1)) + min;
}


/**
	check if ALL inputs and textareas have values
*/
function hasValue(/*input control ID1, ID2, ...*/)                
{                                                                 
    for (var i=0; i<arguments.length; ++i)                        
    {                                                             
        var ctrl = el(arguments[i]);                              
        if (ctrl.tagName == 'INPUT' || ctrl.tagName == 'TEXTAREA')
        {      
            if (ctrl.value == '')                                 
            {
				ctrl.focus();
                return false;                                     
            }                                                     
        }                                                         
        else if (ctrl.tagName == 'SELECT')                        
        {                                                         
            if (ctrl.selectedIndex == -1)                         
            {                
				ctrl.focus();
                return false;                                     
            }                                                     
        }                                                         
    }                                                             
    return true;
}

function anyHasValue(/*input control ID1, ID2, ...*/)
{                                                    
    for (var i=0; i<arguments.length; ++i)           
    {                                                
        if (hasValue(arguments[i]))                  
        {                                            
            return true;                             
        }                                            
    }                                                
    return false;                                    
}  

/**                                                                              
   @param  Object params  add params to url or replace existing                  
 */                                                                              
function setInUri(params, url)                                                   
{
   if (!url)
   {
      url = window.location.href;
   }
   
   for (var nm in params)                                                        
   {                                                                             
      var re = new RegExp('([&\?]?)('+nm+'=?[^&#]*)','g');                       
      if (re.test(url))                                                          
      {                                                                          
         url = url.replace(re, '$1' + nm + (params[nm] ? ('='+params[nm]) : ''));
      }                                                                          
      else                                                                       
      {                                                                          
         var newParam = nm + (params[nm] ? ('=' + params[nm]) : '');             
         if (url.indexOf('&') > 0 || url.indexOf('?') > 0)                       
         {                                                                       
            newParam = '&' + newParam;                                           
         }                                                                       
         else                                                                    
         {                                                                       
            newParam = '?' + newParam;                                           
         }                                                                       
         var iAnchor = url.indexOf('#');                                         
         if (iAnchor >= 0)                                                       
         {                                                                       
            url = url.substr(0,iAnchor) + newParam + url.substr(iAnchor);        
         }                                                                       
         else                                                                    
         {                                                                       
            url += newParam;                                                     
         }                                                                       
      }                                                                          
   }                                                                             
   return url;                                                                   
}  
